import request from '@/utils/request'
import type { ScriptListResponse } from '@/types/script'
// 查询所有剧本
export const getScriptListAPI = (query: { page: number, size: number }) => {
  return request.get<ScriptListResponse>('/script-category/get', {
    params: query
  })
}


// 根据分类id查询剧本
export const getScriptListByCategoryIdAPI = (query: { categoryId: number, page: number, size: number }) => {
  return request.get<ScriptListResponse>('/script-category/getByCategory', {
    params: query
  })
}




// 上传剧本图片
export const uploadScriptImageAPI = (file: File,id:number) => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('id', id.toString())
  return request.post('/script/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export interface ScriptFormData {
  title: string
  author: string
  categoryId: number
  publisherId: number
  price: number
  contentFile: string
  description: string
  status: number
  sold: number
}
// 添加剧本
export const addScriptAPI = (formData: ScriptFormData) => {
  return request.post('/script/commit', formData)
}
